// index page
// ============

define(
    [ 'require', 'zepto', 'wx', 'ejs', 'utils', 'sui' ],
    function(require, $, wx, ejs, utils) {
      return {
        init : function(data) {
          this.initPage();
        },
        
        initPage: function() {
          var that = this;
          var billList= [{
            'name': "提现",
            'description': 'Sara的减肥大计',
            'time': '2018年12月06日 10:35',
            'price': '200',
          },
          {
            'name': "竞猜",
            'description': 'Sara的减肥大计',
            'time': '2018年12月06日 10:35',
            'price': '50',
          },
          {
            'name': "契约金",
            'description': 'Sara的减肥大计',
            'time': '2018年12月06日 10:35',
            'price': '200',
          }]
          
          var html = '<% billList.forEach(function(item, index){%>'
        	    + '<div class="item-content">'
                + '<div class="item-inner">'
                + '<div class="item-title">'
                + '<div class="draw-name"><%= item.name %></div>'
                + '<div class="inner">'
                + '<div><i class="red-circular"></i><%= item.description %></div>'
                + '<div><i class="iconfont icon-time"></i><%= item.time %></div>'
                + '</div>'
                + '</div>'
                + '<div class="item-after color-red"><%=item.price %>元</div>'
                + '</div>'
                + '</div>'
                + '<% }) %>';
            
          var result = ejs.render(html, {
        	  billList: billList
            })
              
          $('.bill-list').html(result);
            /*$.ajax({
              type : 'GET',
              url : window.__CTX__.domain + '/api/profile',
              dataType : 'json',
              timeout : 30000,
              success : function(res) {

                if (res.code == 0) {
                  that.products = res.data.products;
                  $.ajax({
                    type : 'GET',
                    url : window.__CTX__.domain
                        + '/api/products/remaining',
                    dataType : 'json',
                    timeout : 30000,
                    success : function(res) {
                      if(res.code == 0) {
                        that.remaing = res.data.remaining;
                        $.ajax({
                          type : 'GET',
                          url : window.__CTX__.domain + '/api/profile/courses?unionid=' + that.unionid,
                          dataType : 'json',
                          timeout : 30000,
                          success : function(res) {
                            console.log(res);
                            if(res.code == 0) {
                              that.userCourses = res.data.courses;
                              that.userCoursesMap = res.data.coursesMap;
                              that.userCoursesMapSize = Object.keys(res.data.coursesMap).length;
                              var result = ejs.render(html, {
                                productAll : that.products[0],
                                products : that.products,
                                remaing : that.remaing,
                                userCoursesMap: that.userCoursesMap,
                                userCoursesMapSize: that.userCoursesMapSize
                              })
                              $('.course-list').html(result);
                            } else {
                              $.toast("获取课程数据失败");
                            } 
                          },
                          error : function(xhr, type) {
                            alert('Ajax error!')
                          }
                        })
                      } else {
                        $.toast("获取课程数据失败");
                      }

                    },
                    error : function(xhr, type) {
                      alert('Ajax error!')
                    }
                  })
                } else {
                  $.toast("获取课程数据失败");
                }
              },
              error : function(xhr, type) {
                alert('Ajax error!')
              }
            })*/
        }
        
      }
    })